
$(function () {
    initEvent();
    getDaturmType();
    getCity(false,'','iprovince');
    getCity(false,'','wprovince');
    // getBankCity();
    getUserInfo();
    //getInsuranceInfo();

    // 时间选择控件---显示年月日
    $('.calendarTime').mobiscroll().date({
        theme : 'ios',
        lang : 'zh',
        display : 'bottom',
        dateFormat : 'yy-mm-dd',
        showScrollArrows: true
    });

    /*选择上课日*/
    selectSchoolDay($(".class-day span"));
});

/*选择上课日*/
function selectSchoolDay(obj){
    obj.click(function(){
        var index = $(this).index();
        if($(this).hasClass("cur")){
            $(this).removeClass("cur");
        } else {
            $(this).addClass("cur");
        }

        var html = "";
        $(".class-day span.cur").each(function(){
            html += ('周' + $(this).html() + ',');
        })

        var s = html;
        s=s.substring(0,s.length-1); //删除最后一个逗号

        $("#schoolDay").html(s);
    });
}

function initEvent() {
    //发送验证码
    $("#J_getCode").off('click').on('click', function () {
        tele_Phonecode_New();
    });
    //绑定银行卡
    $("#bindBank").off('click').on('click', function () {
        bind_Bank_New();
    });
    //基本信息保存
    $("#msgPeople").off('click').on('click', function () {
        msgPeople();
    });
    //保存紧急联系人
    $("#contactMsg").off('click').on('click', function () {
        contactMsg();
    });
    //影像资料
    $("#yxzlmsgSave").off('click').on('click', function () {
        yxzlmsgSave();
    });
    //工作信息
    $("#workmsgSave").off('click').on('click', function () {
        workmsgSave();
    });
    //提交信息
    $("#submitMsg").off('click').on('click', function () {
        submitMsg();
    });
}
/*预签约唯一码*/
var uniqueCode = ""
/*绑定银行卡--新 2019-01-22*/
function bind_Bank_New() {
    var datas = common.formatFormData('bankInfo');
    if(!checkParams(datas)) return false;
    
    var bankCartNo = $('#idcard').val();//银行卡号
    var phone = $('#banktel').val();//预留手机号
    var phoneCode = $('#phone_code').val();//验证码

    var result = common.checkForm().checkCard(bankCartNo, function (result, error) {
        if (result == false) {
            falert(error);
            return false;
        }
    }).checkMobile(phone, function (result, error) {
        if (result == false) {
            falert(error);
            return false;
        }
    }).value;

    if (result == true) {
        var datas = {
            interface:'users@confirmBindCard', 
            uniqueCode: uniqueCode,
            phoneCode: phoneCode,
            bankCartNo: bankCartNo,
            phone: phone
        };
        common.ajax({
            data: datas,
            success: function (data) {
                if (data.status == '2000') {
                    getTplHtml('bank',$('#bankInfo'));
                    $(".banner1").css("min-height","3.3rem");
                    $(".banner1 .yyz1").show();
                    common.ajax({
                        data: {interface:'users@userInfo'},
                        success: function (data) {
                            if (data.status == '2000') {
                                setTimeout(function(){$('#bankInfo').html(common.formatTemplate(data.result,$('#bankInfo').html()));}, 500);
                            } else if (data.status == '5000') {
                                falert(data.msg);
                            }
                        }
                    });
                    $('#checkSubmit').val(parseInt($('#checkSubmit').val())+1);
                    falert('绑卡成功');
                } else if (data.status == '5000') {
                    falert(data.msg);
                }
            }
        });
    }
}
/*短信验证码验证--新 2019-01-22*/
function tele_Phonecode_New() {
    var phone = $('#banktel').val();
    var bankCartNo = $('#idcard').val();
    var result = common.checkForm().checkCard(bankCartNo, function (result, error) {
        if (result == false) {
            falert(error);
            return false;
        }
    }).checkMobile(phone, function (result, error) {
        if ('' == $.trim(phone) || $.trim(phone) == $("#banktel").attr('placeholder')) {
            falert('请输入手机号码');
            return false;
        } else if (result == false) {
            falert(error);
            return false;
        }
    }).value;
    if (result == true) {
        var datas = {
            interface:'users@preBindCard', 
            phone: phone,
            bankCartNo: bankCartNo
        };
        common.ajax({
            data: datas,
            beforeSend: function () {
                $("#J_getCode").attr("disabled",true);
                common.clearCountDown($("#J_getCode"));
                common.countDown($("#J_getCode"));
            },
            success: function (data) {
                if (data.status == '2000') {
                   $("#J_getCode").attr('disabled',false);
                   uniqueCode = data.result.unique_code;
                } else if (data.status == '5000') {
                    falert(data.msg);
                }
            }
        });

    }
}

//绑定银行卡
/*function bind_Bank() {
    var datas = common.formatFormData('bankInfo');
    if(!checkParams(datas)) return false;
    
    var idcard = $('#idcard').val();//银行卡号
    var phone = $('#banktel').val();//预留手机号

    var result = common.checkForm().checkCard(idcard, function (result, error) {
        if (result == false) {
            falert(error);
            return false;
        }
    }).checkMobile(phone, function (result, error) {
        if (result == false) {
            falert(error);
            return false;
        }
    }).value;

    if (result == true) {
        datas.interface = 'users@bindBank';
        common.ajax({
            data: datas,
            success: function (data) {
                if (data.status == '2000') {
                    getTplHtml('bank',$('#bankInfo'));
                    $(".banner1").css("min-height","3.3rem");
                    $(".banner1 .yyz1").show();
                    common.ajax({
                        data: {interface:'users@userInfo'},
                        success: function (data) {
                            if (data.status == '2000') {
                                setTimeout(function(){$('#bankInfo').html(common.formatTemplate(data.result,$('#bankInfo').html()));}, 500);
                            } else if (data.status == '5000') {
                                falert(data.msg);
                            }
                        }
                    });
                    $('#checkSubmit').val(parseInt($('#checkSubmit').val())+1);
                    falert('绑卡成功');
                } else if (data.status == '5000') {
                    falert(data.msg);
                }
            }
        });
    }
}*/

/*短信验证码验证*/
/*function tele_Phonecode() {
    var phone = $('#banktel').val();

    var result = common.checkForm().checkMobile(phone, function (result, error) {
        if ('' == $.trim(phone) || $.trim(phone) == $("#banktel").attr('placeholder')) {
            falert('请输入手机号码');
            return false;
        } else if (result == false) {
            falert(error);
            return false;
        }
    }).value;

    if (result == true) {
        var datas = {
            interface:'users@sendcode', 
            phone: phone
        };
        common.ajax({
            data: datas,
            beforeSend: function () {
                $("#J_getCode").attr("disabled",true);
                common.clearCountDown($("#J_getCode"));
                common.countDown($("#J_getCode"));
            },
            success: function (data) {
                if (data.status == '2000') {
                   $("#J_getCode").attr('disabled',false);
                }
            }
        });

    }
}*/

// 获取居住地(城市联动)
function getCity(flag,id,objid){
    if(objid == 'icity' || objid == 'iarea' || objid == 'wcity' || objid == 'warea'){
        if('' == id){
            falert('请选择正确的省市区');
            return false;
        }
    }
    id = id || '';
    flag = flag || false;
    var datas = {
        interface:'users@getCity',           
    };
    if(flag && id){
        datas.id = id;
    }
    common.ajax({
        data: datas,
        success: function (data) {
            if (data.status == '2000') {
                if(flag == 'city'){
                    var html = '<option value="" val="">选择市</option>';
                    $('#'+objid).html(html);
                    if(objid == 'wcity'){
                        $('#warea').html('<option value="" val="">选择区</option>');
                    }else if(objid == 'icity'){
                        $('#iarea').html('<option value="" val="">选择区</option>');
                    }
                    html += common.formatTemplate(data.result,'<option value="{city_name}" val="{city_key}">{city_name}</option>',true);
                    $('#'+objid).html(html);
                }else if(flag == 'area'){
                    var html = '<option value="" val="">选择区</option>';
                    html += common.formatTemplate(data.result,'<option value="{city_name}" val="{city_key}">{city_name}</option>',true);  
                    $('#'+objid).html(html);
                }else{
                    var html = '<option value="" val="">选择省</option>';
                    html += common.formatTemplate(data.result,'<option value="{city_name}" val="{city_key}">{city_name}</option>',true);  
                    $('#'+objid).html(html);
                }
             
            } else if (data.status == '5000') {
                falert(data.msg);
            }
        }
    });  
}

// 

// 获取银行城市   2019-01-23添加注释
/*function getBankCity(flag,id,type){
    if(type == '2' || type == '3'){
        if('' == id){
            falert('请选择正确的省市区');
            return false;
        }
    }
    id = id || '';
    flag = flag || false;
    type = type || 1;
    var datas = {
        interface:'users@getBankCity',           
    };
    if(flag && id){
        datas.id = id;
    }
    if(type && id){
        datas.type = type;
    }
    common.ajax({
        data: datas,
        success: function (data) {
            if (data.status == '2000') {
                if(flag == 'city'){
                    $('#area').html('<option value="" val="">选择区</option>');
                    var html = '<option value="" val="">选择市</option>';
                    html += common.formatTemplate(data.result,'<option value="{area_code}" val="{city}">{city}</option>',true);
                    $('#city').html(html);
                }else if(flag == 'area'){
                    var html = '<option value="" val="">选择区</option>';
                    html += common.formatTemplate(data.result,'<option value="{area_code}" val="{area_name}">{area_name}</option>',true);  
                    $('#area').html(html);
                }else{
                    var html = '<option value="" val="">选择省</option>';
                    html += common.formatTemplate(data.result,'<option value="{area_code}" val="{province}">{province}</option>',true);  
                    $('#province').html(html);
                }

            } else if (data.status == '5000') {
                falert(data.msg);
            }
        }
    });
}*/

function getFldInfo(){
    var value = $('#parent').find("option:selected").text()+'->'+$('#child1').find("option:selected").text()+'->'+$('#child2').find("option:selected").text()+'->'+$('#child3').find("option:selected").text();
    $('#uw_fld').val($('#child3').find("option:selected").val());
    $('#uw_fld_name').val(value);
}

var list2 = {'I':['64','65'],'J':['66','69'],'K':['70','71'],'L':['72'],'M':['74'],'O':['79','81'],'P':['82']};
var list2_ = {'64':'互联网和相关服务','65':'软件和信息技术服务业','66':'货币金融服务','69':'其他金融业','70':'房地产业','71':'租赁业','72':'商务服务业','74':'专业技术服务业','79':'居民服务业','81':'其他服务业','82':'教育'};

// 第3级
var list3 = {'64':['642','649'],'65':['659','651'],'66':['663'],'69':['691','693'],'70':['703'],'71':['712'],'72':['723','727','729'],'74':['749'],'79':['791','799'],'81':['819'],'82':['829']};
var list3_ = {'642':'互联网信息服务','649':'其他互联网服务','651':'软件开发','659':'其他信息技术服务业','663':'非货币银行服务','691':'金融信托与管理服务','693':'非金融机构支付服务','703':'房地产中介服务','712':'文化及日用品出租','723':'咨询与调查','727':'旅行社及相关服务','729':'其他商务服务业','749':'其他专业技术服务业','791':'家庭服务','799':'其他居民服务业','819':'其他未列明服务业','829':'技能培训、教育辅助及其他教育'};

//第4级
var list4 = {'642':['6420'],'649':['6490'],'651':['6510'],'659':['6599'],'663':['6631','6633'],'691':['6910'],'693':['6930'],'703':['7030'],'712':['7129'],'723':['7239'],'727':['7279'],'729':['7299'],'749':['7491','7499'],'791':['7910'],'799':['7990'],'819':['8190'],'829':['8299']};
var list4_ = {'6420':'互联网信息服务','6490':'其他互联网服务','6510':'软件开发','6599':'其他未列明信息技术服务业','6631':'金融租赁服务','6633':'典当','6910':'金融信托与管理服务','6930':'非金融机构支付服务','7030':'房地产中介服务','7129':'其他文化及日用品出租','7239':'其他专业咨询','7279':'其他旅行社相关服务','7299':'其他未列明商务服务业','7491':'专业化设计服务','7499':'其他未列明专业技术服务业','7910':'家庭服务','7990':'其他居民服务业','8190':'其他未列明服务业','8299':'其他未列明教育'};

var default_ = '<option value="">请选择</option>';

function clickOpt(num){
    var html1=default_;
     $.each(list2[num],function(key,val){
        html1 += '<option value="'+val+'">'+list2_[val]+'</option>';
         $('#child1').html(html1);
      });
     $('#child2').html(default_);
     $('#child3').html(default_);
     $('#child4').html(default_);

}

function clickOpt1(num,v,list){
    var html2=default_;
     var arr = list3_;
     if(3==num){
       arr = list4_;
     }
     $.each(list,function(key3,val3){
        html2 += '<option value="'+val3+'">'+arr[val3]+'</option>';
         $('#child'+num).html(html2);
      });

}

// 提交个人信息
function msgPeople() {
    var datas = common.formatFormData('msgInfo');
    if(!checkParams(datas)) return false;
    
//    var email = $('#u_email').val();
//
//    var result = common.checkForm().checkEmail(email, function (result, error) {
//        if (result == false) {
//            falert(error);
//            return false;
//        }
//    }).value;
    
    if($("input[name='address']").val().length < 3){
        falert('请输入至少3位以上的详细地址');
        return false;
    }

//    if(result == true){
        datas.interface = 'users@douserInfo';
        common.ajax({
            data: datas,
            success: function (data) {
                if (data.status == '2000') {
                    getTplHtml('msg',$('#msgInfo'));
                    $(".banner3").css("min-height","8.45rem");
                    $(".banner3 .yyz2").show();
                    common.ajax({
                        data: {interface:'users@userInfo'},
                        success: function (data) {
                            if (data.status == '2000') {
                                setTimeout(function(){$('#msgInfo').html(common.formatTemplate(data.result,$('#msgInfo').html()));}, 500);
                            } else if (data.status == '5000') {
                                falert(data.msg);
                            }
                        }
                    });
                    $('#checkSubmit').val(parseInt($('#checkSubmit').val())+1);
                    falert('保存成功');
                } else if (data.status == '5000') {
                    falert(data.msg);
                }
            }
        });
//    }
    
}

// 提交联系人信息
function contactMsg() {
    var contactInfo1 = common.formatFormData('contactInfo1');
    if (!checkParams(contactInfo1))
        return false;
    var contactInfo2 = common.formatFormData('contactInfo2');
    if (!checkParams(contactInfo2))
        return false;
    
    var relationArr = [];
    var phonearr = [];
    var flag = true;
    var nflag = true;
    for (var i = 1; i <= 2; i++) {
        var relation = $("#relation" + i).val();
        var phone = $("#phone" + i).val();
        var name = $("#name" + i).val();
        common.checkForm().checkName(name, function (result, error) {
            if (result == false) {
                falert(error);
                nflag = false;
                return false;
            }else{
                nflag = true;
            }
        });
        common.checkForm().checkMobile(phone, function (result, error) {
            if (result == false) {
                falert(error);
                flag = false;
                return false;
            }else{
                flag = true;
            }
        });
        if (phone) {
            phonearr.push(phone);
        }
        if (relation == '父亲' || relation == '母亲' || relation == '配偶') {
            relationArr.push(relation);
        }
    }
    if(!flag || !nflag){
        return false;
    }
    if (/(\x0f[^\x0f]+)\x0f[\s\S]*\1/.test("\x0f" + relationArr.join("\x0f\x0f") + "\x0f")) {
        falert('两个紧急联系人不能重复');
        return false;
    }
    if (/(\x0f[^\x0f]+)\x0f[\s\S]*\1/.test("\x0f" + phonearr.join("\x0f\x0f") + "\x0f")) {
        falert('手机号不能重复');
        return false;
    }
    
    var arr = [];
    arr.push(contactInfo1);
    arr.push(contactInfo2);
    var datas = new Object;
    datas.relations = arr;
    datas.interface = 'users@doContact';
    common.ajax({
        data: datas,
        success: function (data) {
            if (data.status == '2000') {
                $('#contactMsg').remove();
                getTplHtml('contact1', $('#contactInfo1'));
                getTplHtml('contact2', $('#contactInfo2'));
                $(".banner5").css("min-height", "10.8rem");
                $(".banner5 .yyz5").show();
                common.ajax({
                    data: {interface: 'users@contact'},
                    success: function (data) {
                        if (data.status == '2000') {
                            setTimeout(function () {
                                $('#contactInfo1').html(common.formatTemplate(data.result[0], $('#contactInfo1').html()));
                                $('#contactInfo2').html(common.formatTemplate(data.result[1], $('#contactInfo2').html()));
                            }, 500);
                        } else if (data.status == '5000') {
                            falert(data.msg);
                        }
                    }
                });
                $('#checkSubmit').val(parseInt($('#checkSubmit').val()) + 1);
                falert('保存成功');
            } else if (data.status == '5000') {
                falert(data.msg);
            }
        }
    });
}

// 提交影像资料
function yxzlmsgSave() {
    var flag = true;
    var daturm = [];
    var k = 0;
    $.each($('.userfiles'), function (i, o) {
        if($(o).attr('fileType') == '13'){
            if($('#file13_1').val() == ''){
                flag = false;
                return false;
            }
        }else{
            if($(o).val() == ''){
                flag = false;
                return false;
            }
        }
        
        var file = [$(o).attr('fileType'), $(o).val()];
        daturm.push(file);
    });
    if(!flag){
        falert('请您上传资料');
        return false;
    }
    var datas = new Object;
    datas.daturmInfo = daturm;
    datas.interface = 'users@userUpload';
    if(common.get('id')>0){
        datas.b_id = common.get('id');
    }
    common.ajax({
        data: datas,
        success: function (data) {
            if (data.status == '2000') {
                $('#yxzlmsgSave').remove();
                $('#checkSubmit').val(parseInt($('#checkSubmit').val()) + 1);
                $(".banner6 .yyz4").show();
                falert('保存成功');
            } else if (data.status == '5000') {
                falert(data.msg);
            }
        }
    });
}

function workTab(n){
    var orderFundFlag = $('#orderFundFlag').val();
    $('#biaosTP,#biaos').val(n);
    getTplHtml('workform'+n,$('#workform'));
    getCity(false,'','wprovince');
    $('#uw_city_code').val('');
    if(n == '1'){
        $(".banner4").css("min-height","18.4rem");
    }else if(n == '2'){
        $(".banner4").css("min-height","8.5rem");
    }else if(n == '3'){
        $(".banner4").css("min-height","8.5rem");
        $('#uw_city_code').val('0');
        setTimeout(function(){
            laydate.render({elem: '#school_date',showBottom: false,min: '2010-1-1',max: '2099-1-1',trigger: 'click'});
            $('select').change(function(){  
                if($(this).children('option:selected').val() != ''){
                    $(this).removeClass('selectcolor');
                }else{
                    $(this).addClass('selectcolor');
                }  
            })
        }, 200);
    }
    
    if(n == '3' && orderFundFlag != 'freeloan'){
        $('#img8,#img9').remove();
        var html = '';
        html += '<div class="idcardpic fl" id="img9">';
        html += '<img class="picture portrait" id="imgsrc9" src="/static/images/id1.png" alt="">';
        html += '<input class="upload1" type="file" name="file9" accept="image/*" onchange="file_upload(this, \'9\')">';
        html += '<input type="hidden" id="file9" class="userfiles" fileType="9" value="">';
        html += '<div class="fixpic">学生证或校园卡</div>';
        html += '<div id="uploadpic9"></div>';
        html += '</div>';
        html += '<div class="idcardpic fl" id="img8">';
        html += '<img class="picture portrait" id="imgsrc8" src="/static/images/id4.png" alt="">';
        html += '<input class="upload1" type="file" name="file8" accept="image/*" onchange="file_upload(this, \'8\')">';
        html += '<input type="hidden" id="file8" class="userfiles" fileType="8" value="">';
        html += '<div class="fixpic">学信网截图</div>';
        html += '<div id="uploadpic8"></div>';
        html += '</div>';
        $('#yxzlTabInfo').append(html);
    }else{
        $('#img8,#img9').remove();
    }
    
}

// 提交工作信息
function workmsgSave() {
    var datas = common.formatFormData('workInfo');
    if(!checkParams(datas)) return false;
    
    var biaos = $('#biaos').val();
    var flag = true;
    if(biaos == '3'){
        if($("input[name='com_name']").val().length < 3){
            falert('请输入至少3位以上的学校名称');
            return false;
        }else if($("input[name='indiv_post']").val().length < 2){
            falert('请输入至少2位的专业名称');
            return false;
        }
        flag = common.checkForm().checkTime($('#school_date').val(), function (result, error) {
            if (result == false) {
                falert(error);
                return false;
            }
        }).value;
    }else{
        if($("input[name='com_name']").val().length < 3){
            falert('请输入至少3位以上的单位名称');
            return false;
        }else if($("input[name='com_addr']").val().length < 3){
            falert('请输入至少3位以上的单位地址');
            return false;
        }
    }

    if(flag == true){
        datas.interface = 'users@doworkInfo';     
        common.ajax({
            data: datas,
            success: function (data) {
                if (data.status == '2000') {
                    getTplHtml('work'+biaos,$('#workInfo'));
                    if(biaos == '1'){
                        $(".banner4").css("min-height","13.3rem");
                    }else if(biaos == '2'){
                        $(".banner4").css("min-height","7.25rem");
                    }else if(biaos == '3'){
                        $(".banner4").css("min-height","7.25rem");
                    }
                    $(".banner4 .yyz3").show();
                    common.ajax({
                        data: {interface:'users@workInfo'},
                        success: function (data) {
                            if (data.status == '2000') {
                                if(data.result.cus_flag == '1'){
                                    data.result.cus_flag = '自雇';
                                }else if(data.result.cus_flag == '2'){
                                    data.result.cus_flag = '在职';
                                }else if(data.result.cus_flag == '3'){
                                    data.result.cus_flag = '学生';
                                }
                                setTimeout(function(){$('#workInfo').html(common.formatTemplate(data.result,$('#workInfo').html()));}, 500);
                            } else if (data.status == '5000') {
                                falert(data.msg);
                            }
                        }
                    });
                    $('#checkSubmit').val(parseInt($('#checkSubmit').val())+1);
                    falert('保存成功');
                } else if (data.status == '5000') {
                    falert(data.msg);
                }
            }
        });
    }
}

function getUserInfo(){
    var datas = {
        interface:'users@upUserInfo',
        infoType:'2',
    };
    if(common.get('id')>0){
        datas.b_id = common.get('id');
    }
    common.ajax({
        data: datas,
        success: function (data) {
            if (data.status == '2000') {
                $('#orderFundFlag').val(data.result.orderInfo.fund_name);
                if(data.result.orderInfo.partner_type == '2'){
                    $('#checkSubmit').val(parseInt($('#checkSubmit').val())+1);
                    $(".banner6").remove();
                }
                //$('#userInfo').html(common.formatTemplate(data.result.userInfo,$('#userInfo').html()));
                if(data.result.userInfo.ub_card_no){
                    getTplHtml('bank',$('#bankInfo'));
                    $(".banner1").css("min-height","3.3rem");
                    $(".banner1 .yyz1").show()
                    setTimeout(function(){$('#bankInfo').html(common.formatTemplate(data.result.userInfo,$('#bankInfo').html()));}, 1000);
                    $('#checkSubmit').val(parseInt($('#checkSubmit').val())+1);
                }
                if(data.result.userInfo.u_qq){
                    getTplHtml('msg',$('#msgInfo'));
                    $(".banner3").css("min-height","8.45rem");
                    $(".banner3 .yyz2").show()
                    setTimeout(function(){$('#msgInfo').html(common.formatTemplate(data.result.userInfo,$('#msgInfo').html()));}, 1000);
                    $('#checkSubmit').val(parseInt($('#checkSubmit').val())+1);
                }
                var cus_flag = data.result.workInfo.cus_flag;
                if(data.result.workInfo.cus_flag){
                    $('#biaosTP').val(data.result.workInfo.cus_flag);
                    getTplHtml('work'+data.result.workInfo.cus_flag,$('#workInfo'));
                    if(data.result.workInfo.cus_flag == '1'){
                        $(".banner4").css("min-height","13.3rem");
                    }else if(data.result.workInfo.cus_flag == '2'){
                        $(".banner4").css("min-height","7.2rem");
                    }else if(data.result.workInfo.cus_flag == '3'){
                        $(".banner4").css("min-height","7.2rem");
                    }
                    $(".banner4 .yyz3").show()
                    if(data.result.workInfo.cus_flag == '1'){
                        data.result.workInfo.cus_flag = '自雇';
                    }else if(data.result.workInfo.cus_flag == '2'){
                        data.result.workInfo.cus_flag = '在职';
                    }else if(data.result.workInfo.cus_flag == '3'){
                        data.result.workInfo.cus_flag = '学生';
                    }
                    setTimeout(function(){$('#workInfo').html(common.formatTemplate(data.result.workInfo,$('#workInfo').html()));}, 1000);
                    $('#checkSubmit').val(parseInt($('#checkSubmit').val())+1);
                }
                if(data.result.daturm.length>0){
                    $('#yxzlmsgSave').remove();
                    var imghtml = '';
                    $.each(data.result.daturm, function(i, o) {
                        imghtml += '<div class="idcardpic fl">';
                        imghtml += '<img class="picture portrait" src="'+o.url+'" alt="">';
                        imghtml += '<div class="fixpic">'+o.ud_name+'</div>';
                        imghtml += '</div>';
                    });
                    $('#yxzlTabInfo').html(imghtml);
                    $('#checkSubmit').val(parseInt($('#checkSubmit').val())+1);
                }else{
                    if(cus_flag == '3' && data.result.orderInfo.fund_name != 'freeloan'){
                        var imghtml = '';
                        imghtml += '<div class="idcardpic fl" id="img9">';
                        imghtml += '<img class="picture portrait" id="imgsrc9" src="/static/images/id1.png" alt="">';
                        imghtml += '<input class="upload1" type="file" name="file9" accept="image/*" onchange="file_upload(this, \'9\')">';
                        imghtml += '<input type="hidden" id="file9" class="userfiles" fileType="9" value="">';
                        imghtml += '<div class="fixpic">学生证或校园卡</div>';
                        imghtml += '<div id="uploadpic9"></div>';
                        imghtml += '</div>';
                        imghtml += '<div class="idcardpic fl" id="img8">';
                        imghtml += '<img class="picture portrait" id="imgsrc8" src="/static/images/id4.png" alt="">';
                        imghtml += '<input class="upload1" type="file" name="file8" accept="image/*" onchange="file_upload(this, \'8\')">';
                        imghtml += '<input type="hidden" id="file8" class="userfiles" fileType="8" value="">';
                        imghtml += '<div class="fixpic">学信网截图</div>';
                        imghtml += '<div id="uploadpic8"></div>';
                        imghtml += '</div>';
                        $('#yxzlTabInfo').append(imghtml);
                    }
                }
                
                if(data.result.contact.length>0){
                    $('#contactMsg').remove();
                    getTplHtml('contact1',$('#contactInfo1'));
                    getTplHtml('contact2',$('#contactInfo2'));
                    $(".banner5").css("min-height","10.8rem");
                    $(".banner5 .yyz5").show()
                    setTimeout(function(){
                        $('#contactInfo1').html(common.formatTemplate(data.result.contact[0],$('#contactInfo1').html()));
                        $('#contactInfo2').html(common.formatTemplate(data.result.contact[1],$('#contactInfo2').html()));
                    }, 1000);
                    $('#checkSubmit').val(parseInt($('#checkSubmit').val())+1);
                }
            } else if (data.status == '5000') {
                falert(data.msg);
            }
        }
    });  
}

function getDaturmType(){
    var datas = {
        interface:'users@upUserInfo',
        infoType:'3',
    };
    if(common.get('id')>0){
        datas.b_id = common.get('id');
    }
    common.ajax({
        data: datas,
        success: function (data) {
            if (data.status == '2000') {

                if(data.result.daturmType == null){
                    $('.banner6').remove();
                    $('#checkSubmit').val(parseInt($('#checkSubmit').val())+1);
                    return false;
                }

                if(data.result.daturmType.length>0){
                    var html = '';
                    $.each(data.result.daturmType, function(i, o) {
                        var bz = '';
                        for(var n=1;n<=o.ud_num;n++){
                            if(o.ud_type == '13' && n>1){
                                bz = '(可选)';
                            }
                            html += '<div class="idcardpic fl">';
                            html += '<img class="picture portrait" id="imgsrc'+o.ud_type+'_'+n+'" src="/static/images/p'+o.ud_type+'.png" alt="">';
                            html += '<input class="upload1" type="file" name="file'+o.ud_type+'_'+n+'" accept="image/*" onchange="file_upload(this,\''+o.ud_type+'_'+n+'\')">';
                            html += '<input type="hidden" id="file'+o.ud_type+'_'+n+'" class="userfiles" fileType="'+o.ud_type+'" value="">';
                            html += '<div class="fixpic">'+o.ud_name+bz+'</div>';
                            html += '<div id="uploadpic'+o.ud_type+'_'+n+'"></div>';
                            html += '</div>';
                        }
                    });
                    $('#yxzlTabInfo').html(html);
                }
            } else if (data.status == '5000') {
                falert(data.msg);
            }
        }
    });  
}

// 提交信息
function submitMsg() {
    //var eleNum = 5;
    //// 判断是否选择了保险,元素如果显示就是选择了保险
    //if ($('#insuranceForm').css('display') != 'none') {
    //    eleNum = 6;
    //}
    //if($('#checkSubmit').val() < eleNum){
    if($('#checkSubmit').val() < '5'){
        falert('请您先完善信息');
        return false;
    }
    var datas = {
        interface:'users@submitMsg',           
    };     
    if(common.get('id')>0){
        datas.b_id = common.get('id');
    }
    common.ajax({
        data: datas,
        success: function (data) {
            if (data.status == '2000') {
                falert('提交信息成功',data.result.jumpUrl);
            } else if (data.status == '5000') {
                falert(data.msg);
            }
        }
    });
}

function file_upload(obj,n){
    $('#file'+n).val('');
    common.compress(obj, function(data){  
        $("#imgsrc"+n).attr("src",data[1]);  
        var sendData = data[1].replace('data:'+data[0]+';base64,', '');
        var url = $('#upload_url').val();
        var imgType = data[0].split('/')[1]=='jpeg'?'jpg':data[0].split('/')[1]; 
        $("#uploadpic"+n).removeClass('complete').addClass('uploadpic').html('上传中').show();
        $.post(url,{ext:imgType,content:sendData},function(datas){
            $('#file'+n).val(datas.url);
            if(datas.url){
                $("#uploadpic"+n).removeClass('uploadpic').addClass('complete').html('<img class="u1" src="/static/images/u1.png" alt="">').show();
            }
        },'json');
    }); 
}

function xzSelected(obj,id){
    $("#"+id+" .circle").removeClass("selected");
    $(obj).addClass("selected");
    if(id == 'xz_marriage'){
        var marriage = $('#'+id).find('.selected').attr('value');
        $('#marriage').val(marriage);
    }
    if(id == 'xz_biaos'){
        workTab($('#'+id).find('.selected').attr('value'));
    }
}

// 弹出层
function certiFication(){
     layer.open({
        type: 1,
        title: false,
        closeBtn: 0,
        skin: 'yourclass',
        btn:'知道了',success:function(layero){
          layero.find('.layui-layer-btn').css('text-align', 'center'); 
        },
        shadeClose: false,
        area: ['287px', '163px'],
        content: '您已经进行了实名认证，您不需要再进行实名认证，请完善剩余信息。'
    });
}

function bindBankcard(){
     layer.open({
        type: 1,
        title: false,
        closeBtn: 0,
        skin: 'yourclass',
        btn:'知道了',success:function(layero){
          layero.find('.layui-layer-btn').css('text-align', 'center'); 
        },
        shadeClose: false,
        area: ['287px', '178px'],
        content: '为保证账户资金安全，只能绑定认证用户本人名下的银行卡。'
    });
}

/**
 * 保存保险信息
 */
function insuranceMsg() {
    var datas = common.formatFormData('insuranceInfo');
    if(!checkParams(datas)) return false;
    var flag = true;

    if($("input[name='classHour']").val() <= 0){
        falert('请输入每日培训课时');
        return false;
    } else if($("input[name='startTime']").val().length < 3){
        falert('请输入课程开始时间');
        return false;
    }else if($("input[name='endTime']").val().length < 3){
        falert('请输入课程结束时间');
        return false;
    }else if($("input[name='insuranceEmail']").val() == ''){
        falert('请输入邮箱');
        return false;
    } else if($("input[name='insuranceSchool']").val() == ''){
        falert('请输入学校名称');
        return false;
    } else if($('#schoolDay').text() == '') {
        falert('请选择上课日');
        return false;
    }
    datas.schoolDay = $('#schoolDay').text();
    datas.b_id = common.get('id');
    if(flag == true){
        datas.interface = 'users@saveInsuranceInfo';
        common.ajax({
            data: datas,
            success: function (data) {
                if (data.status == '2000') {
                    $(".banner1 .yyz6").show();
                    $('#insuranceSub').hide();
                    $('#checkSubmit').val(parseInt($('#checkSubmit').val())+1);
                    falert('保存成功');
                } else if (data.status == '5000') {
                    falert(data.msg);
                }
            }
        });
    }
}

function getInsuranceInfo(){
    var datas = {
        interface:'users@upUserInfo',
        infoType:'4',
    };
    common.ajax({
        data: datas,
        success: function (data) {
            if (data.status == '2000') {
                var result = data.result;
                if (result.hasInsurance == 1) {
                    var isFinish = false;
                    if (result.user_course_time && result.training_start_time
                        && result.training_end_time && result.class_day
                        && result.email && result.school && result.isPass == 1) {
                        isFinish = true;
                    }
                    $('#classHour').val(result.user_course_time);
                    $('#startTime').val(result.training_start_time);
                    $('#endTime').val(result.training_end_time);
                    $('#schoolDay').text(result.class_day);
                    // 选中上课日
                    $('.class-day span').each(function(key, value){
                        var cur = '周' + $(this).html();
                        $.each(result.class_day.split(','), function(k, v){
                            if (v == cur) {
                                $(value).addClass('cur');
                            }
                        })
                    })
                    $('#insuranceEmail').val(result.email);
                    $('#insuranceSchool').val(result.school);
                    if (isFinish) {
                        $(".banner1 .yyz6").show();
                        $('#insuranceSub').hide();
                        $('#checkSubmit').val(parseInt($('#checkSubmit').val())+1);
                    }
                } else {
                    $('#insuranceForm').hide();
                }
            } else if (data.status == '5000') {
                $('#insuranceForm').hide();
                falert(data.msg);
            }
        }
    });
}